# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
# $Id: londropadd.pm,v 1.45.4.1 2002/09/13 18:55:57 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
# (Handler to set parameters for assessments
#
# (Handler to resolve ambiguous file locations
#
# (TeX Content Handler
#
# YEAR=2000
# 05/29/00,05/30,10/11 Gerd Kortemeyer)
#
# 10/11,10/12,10/16 Gerd Kortemeyer)
#
# 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
# 12/08,12/12 Gerd Kortemeyer)
#
# 12/26,12/27,12/28,
# YEAR=2001
# 01/01/01,01/15,02/10,02/13,02/14,02/22 Gerd Kortemeyer
# 8/6 Scott Harrison
# Guy Albertelli
# 9/25 Gerd Kortemeyer
# 12/19 Guy Albertelli
# YEAR=2002
# 1/4 Gerd Kortemeyer
package Apache::londropadd;
use strict;
use Apache::lonnet();
use Apache::loncommon();
use Apache::Constants qw(:common :http REDIRECT);
# ================================================================ Print header
sub header {
return(<
$ENV{'course.'.$ENV{'request.course.id'}.'.description'}
Enrollment Manager
ERROR:$error"); } } elsif (!defined(%currentlist)) { $r->print("There are no students currently enrolled.\n"); } else { # Print out the available choices &show_drop_list($r,%currentlist); } } # ============================================== view classlist sub menu_phase_two_view { my $r=shift; $r->print("
ERROR:$error"); } } elsif (!defined(%currentlist)) { $r->print("There are no students currently enrolled.\n"); } else { # Print out the available choices &show_class_list($r,'view',%currentlist); } } # ============================================== view classlist sub menu_phase_two_viewcsv { my $r=shift; my $cid=$ENV{'request.course.id'}; my ($error,%currentlist)=&get_current_classlist ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'}); if (defined($error)) { if ($error =~ /^No such file or directory/) { $r->print("There are no students currently enrolled.\n"); } else { $r->print("
ERROR:$error"); } } elsif (!defined(%currentlist)) { $r->print("There are no students currently enrolled.\n"); } else { &show_class_list($r,'csv',%currentlist); } } # =================================================== Show student list to drop sub show_class_list { my ($r,$mode,%currentlist)=@_; my $cid=$ENV{'request.course.id'}; # Print out header if ($mode eq 'view') { $r->print(<
username | domain | ID | student name | generation | section |
---|---|---|---|---|---|
' :''). 'Internal error: unable to get environment '. 'for '.$sname.' in domain '.$sdom. ( $mode eq 'view' ?' | |||||
$sname | $sdom | $reply{$sname} | $info{'lastname'}, $info{'firstname'} $info{'middlename'} | $info{'generation'} | $ssec |
username | domain | ID | student name | generation | section | |
---|---|---|---|---|---|---|
'. 'Internal error: unable to get environment '. 'for '.$sname.' in domain '.$sdom.' | ||||||
$sname | $sdom | $reply{$sname} | $info{'lastname'}, $info{'firstname'} $info{'middlename'} | $info{'generation'} | $ssec |
END } # ================================================= Drop/Add from uploaded file sub upfile_drop_add { my $r=shift; &Apache::loncommon::load_tmp_file($r); my @studentdata=&Apache::loncommon::upfile_record_sep(); my @keyfields = split(/\,/,$ENV{'form.keyfields'}); my $cid = $ENV{'request.course.id'}; my %fields=(); for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) { if ($ENV{'form.upfile_associate'} eq 'reverse') { if ($ENV{'form.f'.$i} ne 'none') { $fields{$keyfields[$i]}=$ENV{'form.f'.$i}; } } else { $fields{$ENV{'form.f'.$i}}=$keyfields[$i]; } } # my $startdate = $ENV{'form.startdate'}; my $enddate = $ENV{'form.enddate'}; if ($startdate=~/\D/) { $startdate=''; } if ($enddate=~/\D/) { $enddate=''; } # Determine domain and desired host (home server) my $domain=$ENV{'form.lcdomain'}; my $desiredhost = $ENV{'form.lcserver'}; if (lc($desiredhost) eq 'default') { $desiredhost = undef; } else { my %home_servers = &Apache::loncommon::get_library_servers($domain); if (! exists($home_servers{$desiredhost})) { $r->print('Error:'. 'Invalid home server specified'); return; } } # Determine authentication mechanism my $amode = ''; my $genpwd = ''; if ($ENV{'form.login'} eq 'krb') { $amode='krb4'; $genpwd=$ENV{'form.krbarg'}; } elsif ($ENV{'form.login'} eq 'int') { $amode='internal'; if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) { $genpwd=$ENV{'form.intarg'}; } } elsif ($ENV{'form.login'} eq 'loc') { $amode='localauth'; if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) { $genpwd=$ENV{'form.locarg'}; } } unless (($domain=~/\W/) || ($amode eq '')) { ####################################### ## Enroll Students ## ####################################### $r->print('
Unacceptable username: '. $entries{$fields{'username'}}.' for user '. $fname.' '.$mname.' '.$lname.' '.$gen.'
'); } else { # determine section number my $sec=''; my $username=$entries{$fields{'username'}}; if (defined($fields{'sec'})) { if (defined($entries{$fields{'sec'}})) { $sec=$entries{$fields{'sec'}}; } } # determine student id number my $id=''; if (defined($fields{'id'})) { if (defined($entries{$fields{'id'}})) { $id=$entries{$fields{'id'}}; } $id=~tr/A-Z/a-z/; } # determine student password my $password=''; if ($genpwd) { $password=$genpwd; } else { if (defined($fields{'ipwd'})) { if ($entries{$fields{'ipwd'}}) { $password=$entries{$fields{'ipwd'}}; } } } if ($password) { &modifystudent($domain,$username,$cid,$sec, $desiredhost); my $reply=&Apache::lonnet::modifystudent ($domain,$username,$id,$amode,$password, $fname,$mname,$lname,$gen,$sec,$enddate, $startdate,$ENV{'form.forceid'},$desiredhost); if ($reply ne 'ok') { $r->print('
'. 'Error enrolling '.$username.': '. $reply.'
'); } else { $count++; $flushc++; $student{$username}=1; $r->print('. '); if ($flushc>15) { $r->rflush; $flushc=0; } } } else { $r->print("No password for $username
"); } } } } # end of foreach (@studentdata) $r->print('
Processed Students: '.$count); ##################################### # Drop students # ##################################### if ($ENV{'form.fullup'} eq 'yes') { $r->print('
ERROR:$error'); } if (defined(%currentlist)) { # Drop the students foreach (@studentdata) { my %entries=&Apache::loncommon::record_sep($_); unless (($entries{$fields{'username'}} eq '') || (!defined($entries{$fields{'username'}}))) { delete($currentlist{$entries{$fields{'username'}}. ':'.$domain}); } } # Print out list of dropped students &show_drop_list($r,%currentlist); } else { $r->print("There are no students currently enrolled.\n"); } } } # end of unless } # ================================================================== Phase four sub drop_student_list { my $r=shift; my $count=0; my @droplist; if (ref($ENV{'form.droplist'})) { @droplist = @{$ENV{'form.droplist'}}; } else { @droplist = ($ENV{'form.droplist'}); } foreach (@droplist) { my ($uname,$udom)=split(/\:/,$_); my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'}); if ($result eq 'ok' || $result eq 'ok:') { $r->print('Dropped '.$uname.' at '.$udom.'
Dropped '.$count.' student(s).'); $r->print('
Re-enrollment will re-activate data.'); } # ================================================================ Main Handler sub handler { my $r=shift; if ($r->header_only) { $r->content_type('text/html'); $r->send_http_header; return OK; } # Needs to be in a course if (($ENV{'request.course.fn'}) && (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'}))) { # Start page $r->content_type('text/html') if (! exists($ENV{'form.viewcsv'})); $r->send_http_header; $r->print(&header()) if (! exists($ENV{'form.viewcsv'})); # Phase one, initial screen unless ($ENV{'form.phase'}) { &menu_phase_one($r); } # Phase two if ($ENV{'form.associate'} eq 'Reverse Association') { $ENV{'form.phase'} = 'two'; if ( $ENV{'form.upfile_associate'} ne 'reverse' ) { $ENV{'form.upfile_associate'} = 'reverse'; } else { $ENV{'form.upfile_associate'} = 'forward'; } } if ($ENV{'form.phase'} eq 'two') { if ($ENV{'form.fileupload'}) { &menu_phase_two_upload($r); } elsif ($ENV{'form.enroll'}) { &menu_phase_two_enroll($r); } elsif ($ENV{'form.drop'}) { &menu_phase_two_drop($r); } elsif ($ENV{'form.view'}) { &menu_phase_two_view($r); } elsif ($ENV{'form.viewcsv'}) { &menu_phase_two_viewcsv($r); } } # Phase three if ($ENV{'form.phase'} eq 'three') { if ($ENV{'form.datatoken'}) { &upfile_drop_add($r); } } # Phase four if ($ENV{'form.phase'} eq 'four') { &drop_student_list($r); } # Phase five if ($ENV{'form.phase'} eq 'five') { &enroll_single_student($r); } # End $r->print('