--- loncom/interface/Attic/londropadd.pm 2002/04/16 19:08:49 1.25
+++ loncom/interface/Attic/londropadd.pm 2006/04/26 14:52:22 1.140
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.25 2002/04/16 19:08:49 matthew Exp $
+# $Id: londropadd.pm,v 1.140 2006/04/26 14:52:22 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,276 +25,431 @@
#
# 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::lonnet;
use Apache::loncommon();
+use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
+use Spreadsheet::WriteExcel;
+use Apache::lonstathelpers();
+use Apache::lonlocal;
-# ================================================================ Print header
-
+###############################################################
+###############################################################
sub header {
- my $r=shift;
- $r->print(<
-
Drop/Add Students
-
\n".'\n
\n";
+ $Str .= ''."
\n";
+ $Str .= &mt('Note: for large courses, this operation may be time '.
+ 'consuming');
+ $r->print($Str);
+ return;
+}
+
+###############################################################
+###############################################################
+sub print_upload_manager_form {
my $r=shift;
+
+ my $firstLine;
my $datatoken;
- if (!$ENV{'form.datatoken'}) {
+ if (!$env{'form.datatoken'}) {
$datatoken=&Apache::loncommon::upfile_store($r);
} else {
- $datatoken=$ENV{'form.datatoken'};
+ $datatoken=$env{'form.datatoken'};
&Apache::loncommon::load_tmp_file($r);
}
my @records=&Apache::loncommon::upfile_record_sep();
+ if($env{'form.noFirstLine'}){
+ $firstLine=shift(@records);
+ }
my $total=$#records;
my $distotal=$total+1;
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
my $today=time;
my $halfyear=$today+15552000;
- my $defdom=$r->dir_config('lonDefDomain');
- &phase_two_header($r,$datatoken,$distotal,$krbdefdom);
+ #
+ # Restore memorized settings
+ &Apache::loncommon::restore_course_settings
+ ('enrollment_upload',{ 'username_choice' => 'scalar', # column settings
+ 'names_choice' => 'scalar',
+ 'fname_choice' => 'scalar',
+ 'mname_choice' => 'scalar',
+ 'lname_choice' => 'scalar',
+ 'gen_choice' => 'scalar',
+ 'id_choice' => 'scalar',
+ 'sec_choice' => 'scalar',
+ 'ipwd_choice' => 'scalar',
+ 'email_choice' => 'scalar',
+ });
+ #
+ # Determine kerberos parameters as appropriate
+ my $defdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my ($krbdef,$krbdefdom) =
+ &Apache::loncommon::get_kerberos_defaults($defdom);
+ #
+ &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
my $i;
my $keyfields;
if ($total>=0) {
- my @d=(['username','Username'],['names','Last Name, First Names'],
- ['fname','First Name'],['mname','Middle Names/Initials'],
- ['lname','Last Name'],['gen','Generation'],
- ['id','ID/Student Number'],['sec','Group/Section'],
- ['ipwd','Initial Password']);
- if ($ENV{'form.upfile_associate'} eq 'reverse') {
+ my @field=
+ (['username',&mt('Username'), $env{'form.username_choice'}],
+ ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
+ ['fname',&mt('First Name'), $env{'form.fname_choice'}],
+ ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
+ ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
+ ['gen', &mt('Generation'), $env{'form.gen_choice'}],
+ ['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
+ ['sec', &mt('Group/Section'), $env{'form.sec_choice'}],
+ ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
+ ['email',&mt('EMail Address'), $env{'form.email_choice'}]);
+ if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
- $i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
- foreach (@d) { $keyfields.=$_->[0].','; }
+ $i=&Apache::loncommon::csv_print_select_table($r,\@records,
+ \@field);
+ foreach (@field) {
+ $keyfields.=$_->[0].',';
+ }
chop($keyfields);
} else {
- unshift(@d,['none','']);
- $i=&Apache::loncommon::csv_samples_select_table($r,\@records,\@d);
+ unshift(@field,['none','']);
+ $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
+ \@field);
my %sone=&Apache::loncommon::record_sep($records[0]);
$keyfields=join(',',sort(keys(%sone)));
}
}
- &phase_two_end($r,$i,$keyfields,$defdom,$today,$halfyear);
+ &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
}
-# ======================================================= Enroll single student
-
+###############################################################
+###############################################################
sub enroll_single_student {
my $r=shift;
- $r->print('
'.&mt('Enrolling').' '.$env{'form.cuname'}." \@ ". + $env{'form.lcdomain'}.'
'); + if (($env{'form.cuname'})&&($env{'form.cuname'}!~/\W/)&& + ($env{'form.lcdomain'})&&($env{'form.lcdomain'}!~/\W/)) { + # Deal with home server selection + 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(''.&mt('Error').':'. + &mt('Invalid home server specified')); + return; + } + } + $r->print(" ".&mt('with server')." $desiredhost :") if (defined($desiredhost)); + # End of home server selection logic my $amode=''; my $genpwd=''; - if ($ENV{'form.login'} eq 'krb') { - $amode='krb4'; - $genpwd=$ENV{'form.krbdom'}; - } elsif ($ENV{'form.login'} eq 'int') { - $amode='internal'; - $genpwd=$ENV{'form.intpwd'}; - } elsif ($ENV{'form.login'} eq 'loc') { + if ($env{'form.login'} eq 'krb') { + $amode='krb'; + $amode.=$env{'form.krbver'}; + $genpwd=$env{'form.krbarg'}; + } elsif ($env{'form.login'} eq 'int') { + $amode='internal'; + $genpwd=$env{'form.intarg'}; + } elsif ($env{'form.login'} eq 'loc') { $amode='localauth'; - $genpwd=$ENV{'form.locarg'}; + $genpwd=$env{'form.locarg'}; if (!$genpwd) { $genpwd=" "; } } - if (($amode) && ($genpwd)) { - &dropstudent($ENV{'form.cdomain'},$ENV{'form.cuname'}, - $ENV{'request.course.id'},$ENV{'form.csec'}); - $r->print(&Apache::lonnet::modifystudent - ($ENV{'form.cdomain'},$ENV{'form.cuname'}, - $ENV{'form.cstid'},$amode,$genpwd, - $ENV{'form.cfirst'},$ENV{'form.cmiddle'}, - $ENV{'form.clast'},$ENV{'form.cgen'}, - $ENV{'form.csec'},$ENV{'form.enddate'}, - $ENV{'form.startdate'},$ENV{'form.forceid'})); + my $home = &Apache::lonnet::homeserver($env{'form.cuname'}, + $env{'form.lcdomain'}); + if ((($amode) && ($genpwd)) || ($home ne 'no_host')) { + # Clean out any old roles the student has in this class. + &modifystudent($env{'form.lcdomain'},$env{'form.cuname'}, + $env{'request.course.id'},$env{'form.csec'}, + $desiredhost); + my $login_result = &Apache::lonnet::modifystudent + ($env{'form.lcdomain'},$env{'form.cuname'}, + $env{'form.cstid'},$amode,$genpwd, + $env{'form.cfirst'},$env{'form.cmiddle'}, + $env{'form.clast'},$env{'form.cgen'}, + $env{'form.csec'},$enddate, + $startdate,$env{'form.forceid'}, + $desiredhost,$env{'form.emailaddress'}); + if ($login_result =~ /^ok/) { + $r->print($login_result); + $r->print("".&mt('If active, the new role will be available when the student next logs in to LON-CAPA.')."
"); + } else { + $r->print(&mt('unable to enroll').": ".$login_result); + } } else { - $r->print('Invalid login mode or password'); - } + $r->print(''.&mt('ERROR').' '); + if ($amode =~ /^krb/) { + $r->print(&mt('Missing Kerberos domain information.').' '); + } else { + $r->print(&mt('Invalid login mode or password.').' '); + } + $r->print(''.&mt('Unable to enroll').' '.$env{'form.cuname'}.'.
'); + } + } else { + $r->print(&mt('Invalid username or domain')); + } +} + +sub setup_date_selectors { + my ($starttime,$endtime,$mode) = @_; + if (! defined($starttime)) { + $starttime = time; + unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') { + if (exists($env{'course.'.$env{'request.course.id'}. + '.default_enrollment_start_date'})) { + $starttime = $env{'course.'.$env{'request.course.id'}. + '.default_enrollment_start_date'}; + } + } + } + if (! defined($endtime)) { + $endtime = time+(6*30*24*60*60); # 6 months from now, approx + unless ($mode eq 'createcourse') { + if (exists($env{'course.'.$env{'request.course.id'}. + '.default_enrollment_end_date'})) { + $endtime = $env{'course.'.$env{'request.course.id'}. + '.default_enrollment_end_date'}; + } + } + } + my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform', + 'startdate', + $starttime); + my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform', + 'enddate', + $endtime); + if ($mode eq 'create_enrolldates') { + $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs', + 'startenroll', + $starttime); + $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs', + 'endenroll', + $endtime); + } + if ($mode eq 'create_defaultdates') { + $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs', + 'startaccess', + $starttime); + $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs', + 'endaccess', + $endtime); + } + return ($startdateform,$enddateform); +} + +sub get_dates_from_form { + my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate'); + my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate'); + if ($env{'form.no_end_date'}) { + $enddate = 0; + } + return ($startdate,$enddate); +} + +sub date_setting_table { + my ($starttime,$endtime,$mode) = @_; + my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode); + my $dateDefault = ''.&mt('Starting Date').' | '. + ''.$startform.' | '. + ''.$dateDefault.' | '."
'.&mt('Ending Date').' | '. + ''.$endform.' | '. + ''.$perpetual.' | '."
$lt{'usr'}: | +|
---|---|
$lt{'dom'}: | +$domform |
+ | + + |
$lt{'fn'}: | +|
---|---|
$lt{'mn'}: | +|
$lt{'ln'}: | +|
$lt{'gen'}: | +|
$lt{'hs'}: | +$homeserver_form |
$lt{'mail'}: | +
$lt{'fn'}: | ++ + |
---|---|
$lt{'mn'}: | ++ + |
$lt{'ln'}: | ++ + |
$lt{'gen'}: | ++ + |
$lt{'mail'}: | ++ + |
- -ID/Student Number:
- -Group/Section:
- -
-Domain:
-Note: login settings below will not take effect if the user already exists
- - -Kerberos authenticated with domain -
- -Internally authenticated (with initial password -) + +$user_data_html + +
$lt{'gs'}: +
+$date_table +
+- -Local Authentication with argument - +$lt{'idsn'}: +
+ +
+
--
-
-
-ENDSENROLL
+END
+ return;
}
# ========================================================= Menu Phase Two Drop
-
-sub menu_phase_two_drop {
+sub print_drop_menu {
my $r=shift;
- my $cid=$ENV{'request.course.id'};
- my $classlst=&Apache::lonnet::reply
- ('dump:'.$ENV{'course.'.$cid.'.domain'}.':'.
- $ENV{'course.'.$cid.'.num'}.':classlist',
- $ENV{'course.'.$cid.'.home'});
- my %currentlist=();
- my $now=time;
- unless ($classlst=~/^error\:/) {
- foreach (split(/\&/,$classlst)) {
- my ($name,$value)=split(/\=/,$_);
- my ($end,$start)=split(/\:/,
- &Apache::lonnet::unescape($value));
- my $active=1;
- if (($end) && ($now>$end)) { $active=0; }
- if ($active) {
- $currentlist{&Apache::lonnet::unescape($name)}=1;
+ $r->print("
\n"); + if ($env{'form.action'} ne 'modifystudent') { + my %lt=&Apache::lonlocal::texthash('csv' => "CSV", + 'excel' => "Excel", + 'html' => 'HTML'); + my $output_selector = ''; + $r->print(&mt('Output Format: [_1]',$output_selector).(' 'x3)); + } + $r->print(&mt('Student Status: [_1]',$status_select)."\n"); + $r->print(''. + "\n
\n"); + # + # Print the classlist + $r->print('+".&Apache::loncommon::start_data_table()." +
'.&mt('manual').' | |
'. + &mt('Your Excel spreadsheet').' '.&mt('is ready for download').'.
'."\n"); + } elsif ($mode eq 'csv') { + close($CSVfile); + $r->print(''. + &mt('Your CSV file').' is ready for download.'. + "\n"); + $r->rflush(); + } + if ($mode eq 'autoenroll') { + return ($studentcount,$autocount,$manualcount,$lockcount,$unlockcount); + } + return; +} + + +# +# print out form for modification of a single students data +# +sub print_modify_student_form { + my $r = shift(); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['sdom','sname']); + my $sname = $env{'form.sname'}; + my $sdom = $env{'form.sdom'}; + my $sortby = $env{'form.sortby'}; + # determine the students name information + my %info=&Apache::lonnet::get('environment', + ['firstname','middlename', + 'lastname','generation','id'], + $sdom, $sname); + my ($tmp) = keys(%info); + if ($tmp =~ /^(con_lost|error|no_such_host)/i) { + $r->print(''.&mt('Error').''. + ''. + &mt('Unable to retrieve environment data for').' '.$sname. + &mt('in domain').' '.$sdom.'
'. + &mt('Please contact your LON-CAPA administrator regarding this situation.').'
'.&Apache::loncommon::end_page()); + return; + } + # determine the students starting and ending times and section + my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom); + if ($starttime =~ /^error/) { + $r->print(''.$starttime.'
'); + return; + } + # + # Deal with date forms + my $current_date_description = ''; + my $textdate = ''; + + if (! defined($starttime) || $starttime == 0) { + $current_date_description = &mt('Current Starting Date: not set'). + '+$lt{'sn'} +
$lt{'fn'} | $lt{'mn'} | $lt{'ln'} | $lt{'gen'} |
---|---|---|---|
+ | + | + | + |
+$lt{'sid'}: +
+ +
+$lt{'sec'}: +
+$current_date_description
+$date_table
+ +END + $r->print(&Apache::loncommon::end_page()); + return; +} + +# +# modify a single students section +# +sub modify_single_student { + my ($r) = @_; + # + # Remove non alphanumeric values from the section + $env{'form.section'} =~ s/\W//g; + # + # Do the date defaults first + my ($starttime,$endtime) = &get_dates_from_form(); + if ($env{'form.makedatesdefault'}) { + $r->print(&make_dates_default($starttime,$endtime)); + } + # Get the 'sortby' and 'Status' variables so the user goes back to their + # previous screen + my $sortby = $env{'form.sortby'}; + my $status = $env{'form.Status'}; + # + # We always need this information + my $slogin = $env{'form.slogin'}; + my $sdom = $env{'form.sdomain'}; + # + # Get the old data + my %old=&Apache::lonnet::get('environment', + ['firstname','middlename', + 'lastname','generation','id'], + $sdom, $slogin); + $old{'section'} = &Apache::lonnet::getsection($sdom,$slogin, + $env{'request.course.id'}); + my ($tmp) = keys(%old); + if ($tmp =~ /^(con_lost|error|no_such_host)/i) { + $r->print(&mt('There was an error determining the environment values for')." $slogin \@ $sdom."); + return; + } + undef $tmp; + # + # Get the new data + my $firstname = $env{'form.firstname'}; + my $middlename = $env{'form.middlename'}; + my $lastname = $env{'form.lastname'}; + my $generation = $env{'form.generation'}; + my $section = $env{'form.section'}; + my $courseid = $env{'request.course.id'}; + my $sid = $env{'form.id'}; + my $displayable_starttime = localtime($starttime); + my $displayable_endtime = localtime($endtime); + # + # check for forceid override + if ((defined($old{'id'})) && ($old{'id'} ne '') && + ($sid ne $old{'id'}) && (! exists($env{'form.forceid'}))) { + $r->print("".&mt('You changed the students id but did not disable the ID change safeguard. The students id will not be changed.').""); + $sid = $old{'id'}; + } + # + # talk to the user about what we are going to do + my %lt=&Apache::lonlocal::texthash( + 'mdu' => "Modifying data for user", + 'si' => "Student Information", + 'fd' => "Field", + 'ov' => "Old Value", + 'nv' => "New Value", + 'fn' => "First name", + 'mn' => "Middle name", + 'ln' => "Last name", + 'gen' => "Generation", + 'sec' => "Section", + 'ri' => "Role Information", + 'st' => "Start Time", + 'et' => "End Time", + ); + $r->print(<$lt{'fd'} | +$lt{'ov'} | +$lt{'nv'} | +
---|---|---|
$lt{'fn'} | +$old{'firstname'} | +$firstname | +
$lt{'mn'} | +$old{'middlename'} | +$middlename | +
$lt{'ln'} | +$old{'lastname'} | +$lastname | +
$lt{'gen'} | +$old{'generation'} | +$generation | +
ID | +$old{'id'} | +$sid | +
$lt{'sec'} | +$old{'section'} | +$section | +
$lt{'st'}: | $displayable_starttime |
$lt{'et'}: | $displayable_endtime |
+END
+ #
+ # Send request(s) to modify data (final undef is for 'desiredhost',
+ # which is a moot point because the student already has an account.
+ my $modify_section_results = &modifystudent($sdom,$slogin,
+ $env{'request.course.id'},
+ $section,undef);
+ if ($modify_section_results !~ /^ok/) {
+ $r->print(&mt('An error occured during the attempt to change the section for this student.')."
+
+
+
+$Masd
+END
+ $r->print(&Apache::loncommon::end_page());
+ return;
+}
+
+sub get_enrollment_data {
+ my ($sname,$sdomain) = @_;
+ my $courseid = $env{'request.course.id'};
+ $courseid =~ s:_:/:g;
+ my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
+ my ($tmp) = keys(%roles);
+ # Bail out if we were unable to get the students roles
+ return ('error'.$tmp) if ($tmp =~ /^(con_lost|error|no_such_host)/i);
+ # Go through the roles looking for enrollment in this course
+ my ($end,$start) = (undef,undef);
+ my $section = '';
+ my $count = scalar(keys(%roles));
+ while (my ($course,$role) = each(%roles)) {
+ if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
+ #
+ # Get active role
+ $section=$1;
+ (undef,$end,$start)=split(/\_/,$role);
+ my $now=time;
+ my $notactive=0;
+ if ($start) {
+ if ($now<$start) { $notactive=1; }
+ }
+ if ($end) {
+ if ($now>$end) { $notactive=1; }
+ }
+ unless ($notactive) { return ($start,$end,$section); }
+ }
+ }
+ return ($start,$end,$section);
+}
+
+#################################################
+#################################################
+
+=pod
+=item show_drop_list
+
+Display a list of students to drop
+Inputs:
+
+=over 4
+
+=item $r, Apache request
+
+=item $classlist, hash pointer returned from loncoursedata::get_classlist();
+
+=item $keylist, array pointer returned from loncoursedata::get_classlist()
+which describes the order elements are stored in the %$classlist values.
+
+=item $nosort, if true, sorting links are omitted.
+
+=back
+
+=cut
+
+#################################################
+#################################################
sub show_drop_list {
- my ($r,%currentlist)=@_;
- my $cid=$ENV{'request.course.id'};
+ my ($r,$classlist,$keylist,$nosort)=@_;
+ my $cid=$env{'request.course.id'};
+ if (! exists($env{'form.sortby'})) {
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['sortby']);
+ }
+ my $sortby = $env{'form.sortby'};
+ if ($sortby !~ /^(username|domain|section|fullname|id|start|end)$/) {
+ $sortby = 'username';
+ }
+ #
+ my $action = "drop";
+ $r->print(<
+
+END
+
+my %lt=&Apache::lonlocal::texthash('usrn' => "username",
+ 'dom' => "domain",
+ 'sn' => "student name",
+ 'sec' => "section",
+ 'start' => "start date",
+ 'end' => "end date",
+ );
+ if ($nosort) {
+ $r->print(&Apache::loncommon::start_data_table());
+ $r->print(<
");
+ }
+ my $roleresults = &Apache::lonnet::modifystudent
+ ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
+ $generation,$section,$endtime,$starttime,$env{'form.forceid'});
+ if ($roleresults eq 'refused' ) {
+ $r->print(&mt('Your request to change the role information for this student was refused. You do not appear to have sufficient authority to change student information.'));
+ } elsif ($roleresults !~ /ok/) {
+ $r->print(&mt('An error occurred during the attempt to change the role information for this student.')."
".
+ &mt('The error reported was')." ".
+ $roleresults);
+ &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
+ " data for ".$slogin." \@ ".$sdom." by ".
+ $env{'user.name'}." \@ ".$env{'user.domain'}.
+ ":".$roleresults);
+ } else { # everything is okay!
+ $r->print(&mt('Student information updated successfully.')."
".
+ &mt('The student must log out and log in again to see these changes.'));
+ }
+ my $Masd=&mt('Modify another students data');
+ $r->print(<
+ $lt{'usrn'}
+ $lt{'dom'}
+ ID
+ $lt{'sn'}
+ $lt{'sec'}
+ $lt{'start'}
+ $lt{'end'}
+
+END
+
+ } else {
+ $r->print(&Apache::loncommon::start_data_table());
+ $r->print(<
+
+ $lt{'usrn'}
+
+ $lt{'dom'}
+
+ ID
+
+ $lt{'sn'}
+
+ $lt{'sec'}
+
+ $lt{'start'}
+
+ $lt{'end'}
+
+
+END
+ }
+ #
+ # Sort the students
+ my %index;
+ my $i;
+ foreach (@$keylist) {
+ $index{$_} = $i++;
}
- $r->print('
+ + +
+END + return; } -# ================================================= Drop/Add from uploaded file +# +# Print out the initial form to get the courselist file +# +sub print_first_courselist_upload_form { + my $r=shift; + my $str; + $str = ''; + $str .= ''; + $str .= ''; + $str .= "\n"; + $str .= ''."\n"; + $str .= '
\n"; + $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List", + &mt("How do I create a class list from a spreadsheet")). + "\n"); my $count=0; my $flushc=0; my %student=(); -# ----------------------------------------------------------- Get new classlist -# --------------------------------------------------------- Enroll new students + # Get new classlist foreach (@studentdata) { my %entries=&Apache::loncommon::record_sep($_); + # Determine student name unless (($entries{$fields{'username'}} eq '') || (!defined($entries{$fields{'username'}}))) { - my $fname=''; my $mname=''; my $lname=''; my $gen=''; + my ($fname, $mname, $lname,$gen) = ('','','',''); if (defined($fields{'names'})) { - ($lname,$fname,$mname)= - ($entries{$fields{'names'}}=~/([^\,]+)\,\s*(\w+)\s*(.*)$/); + ($lname,$fname,$mname)=($entries{$fields{'names'}}=~ + /([^\,]+)\,\s*(\w+)\s*(.*)$/); } else { if (defined($fields{'fname'})) { $fname=$entries{$fields{'fname'}}; @@ -772,10 +2171,12 @@ sub upfile_drop_add { } } if ($entries{$fields{'username'}}=~/\W/) { - $r->print('
Unacceptable username: '. - $entries{$fields{'username'}}.' for user '. - $fname.' '.$mname.' '.$lname.' '.$gen.'
');
+ $r->print('
'.
+ &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
+ $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
+ '');
} else {
+ # determine section number
my $sec='';
my $username=$entries{$fields{'username'}};
if (defined($fields{'sec'})) {
@@ -783,6 +2184,9 @@ sub upfile_drop_add {
$sec=$entries{$fields{'sec'}};
}
}
+ # remove non alphanumeric values from section
+ $sec =~ s/\W//g;
+ # determine student id number
my $id='';
if (defined($fields{'id'})) {
if (defined($entries{$fields{'id'}})) {
@@ -790,6 +2194,15 @@ sub upfile_drop_add {
}
$id=~tr/A-Z/a-z/;
}
+ # determine email address
+ my $email='';
+ if (defined($fields{'email'})) {
+ if (defined($entries{$fields{'email'}})) {
+ $email=$entries{$fields{'email'}};
+ unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
+ }
+ }
+ # determine student password
my $password='';
if ($genpwd) {
$password=$genpwd;
@@ -800,15 +2213,23 @@ sub upfile_drop_add {
}
}
}
- if ($password) {
- &dropstudent($domain,$username,$cid,$sec);
+ # Clean up whitespace
+ foreach (\$domain,\$username,\$id,\$fname,\$mname,
+ \$lname,\$gen,\$sec) {
+ $$_ =~ s/(\s+$|^\s+)//g;
+ }
+ if ($password || $env{'form.login'} eq 'loc') {
+ &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'});
- unless ($reply eq 'ok') {
- $r->print(
- "
Error enrolling $username: $reply
");
+ $startdate,$env{'form.forceid'},$desiredhost,
+ $email);
+ if ($reply ne 'ok') {
+ $reply =~ s/^error://;
+ $r->print('
'.
+ &mt('[_1]: Unable to enroll: [_2]',$username,$reply));
} else {
$count++; $flushc++;
$student{$username}=1;
@@ -819,135 +2240,254 @@ sub upfile_drop_add {
}
}
} else {
- $r->print("
No password for $username
");
+ $r->print('
'.
+ &mt('[_1]: Unable to enroll. No password specified.',$username)
+ );
}
}
- }
- }
- $r->print('
Processed Students: '.$count); -# --------------------------------------------------------------- Drop students - if ($ENV{'form.fullup'} eq 'yes') { - $r->print('
\n".&mt('Processed [_1] student(s).',$count). + "
\n"); + $r->print("\n". + &mt('If active, the new role will be available when the '. + 'students next log in to LON-CAPA.')."
\n"); + ##################################### + # Drop students # + ##################################### + if ($env{'form.fullup'} eq 'yes') { + $r->print('Dropped '.$count.' student(s).'); - $r->print('
Re-enrollment will re-activate data.'); + $r->print('
'.&mt('Dropped [_1] student(s).',$count).'
'); + $r->print(''.&mt('Re-enrollment will re-activate data.')) if ($count); } -# ================================================================ Main Handler +################################################################### +################################################################### + +=pod + +=item &handler + +The typical handler you see in all these modules. Takes $r, the +http request, as an argument. + +The response to the request is governed by two form variables + + form.action form.state response + --------------------------------------------------- + undefined undefined print main menu + upload undefined print courselist upload menu + upload got_file deal with uploaded file, + print the upload managing menu + upload enrolling enroll students based on upload + drop undefined print the classlist ready to drop + drop done drop the selected students + enrollstudent undefined print student username domain form + enrollstudent gotusername print single student enroll menu + enrollstudent enrolling enroll student + classlist undefined print html classlist + classlist csv print csv classlist + modifystudent undefined print classlist to select student to modify + modifystudent selected print modify student menu + modifystudent done make modifications to student record + +=cut +################################################################### +################################################################### sub handler { - my $r=shift; - $Apache::lonxml::debug=1; - 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'); - $r->send_http_header; - &header($r); -# --------------------------------------------------- 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); - } - } -# ----------------------------------------------------------------- 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('