--- loncom/interface/Attic/londropadd.pm 2003/06/20 20:57:44 1.68
+++ loncom/interface/Attic/londropadd.pm 2003/11/05 20:55:59 1.87
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.68 2003/06/20 20:57:44 matthew Exp $
+# $Id: londropadd.pm,v 1.87 2003/11/05 20:55:59 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -32,7 +32,7 @@
# (TeX Content Handler
#
###############################################################
-###############################################################
+##############################################################
package Apache::londropadd;
@@ -42,6 +42,7 @@ use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
use Spreadsheet::WriteExcel;
+use Apache::lonlocal;
###############################################################
###############################################################
@@ -79,13 +80,16 @@ sub modifystudent {
# We are in this course
my $section=$1;
$section='' if ($course eq $courseid.'_st');
- if ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
+ if (defined($csec) && $section eq $csec) {
+ $result .= 'ok:';
+ } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
my (undef,$end,$start)=split(/\_/,$roles{$course});
my $now=time;
# if this is an active role
if (!($start && ($now<$start)) || !($end && ($now>$end))) {
my $reply=&Apache::lonnet::modifystudent
- ($udom,$unam,'','','','','','','',
+ # dom name id mode pass f m l g
+ ($udom,$unam,'', '', '',undef,undef,undef,undef,
$section,time,undef,undef,$desiredhost);
$result .= $reply.':';
}
@@ -151,7 +155,7 @@ sub print_main_menu {
@@ -182,6 +186,7 @@ sub print_upload_manager_header {
$javascript=&upload_manager_javascript_forward_associate();
}
my $javascript_validations=&javascript_validations($krbdefdom);
+ my $checked=(($ENV{'form.noFirstLine'})?' checked="1"':'');
$r->print(<Uploading Class List
@@ -195,6 +200,7 @@ to this page if the data selected is ins
+Ignore First Line
@@ -215,7 +221,7 @@ sub javascript_validations {
my $authheader = &Apache::loncommon::authform_header(%param);
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
return (<dir_config('lonDefDomain');
+ 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);
@@ -496,7 +537,8 @@ sub print_upload_manager_form {
['gen','Generation'],
['id','ID/Student Number'],
['sec','Group/Section'],
- ['ipwd','Initial Password']);
+ ['ipwd','Initial Password'],
+ ['email','EMail Address']);
if ($ENV{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
@@ -515,6 +557,8 @@ sub print_upload_manager_form {
# ======================================================= Enroll single student
sub enroll_single_student {
my $r=shift;
+ # Remove non alphanumeric values from section
+ $ENV{'form.csec'}=~s/\W//g;
#
# We do the dates first because the action of making them the defaul
# in the course is entirely seperate from the action of enrolling the
@@ -582,10 +626,14 @@ sub enroll_single_student {
$r->print("unable to enroll: ".$login_result);
}
} else {
- $r->print('
ERROR '.
- 'Invalid login mode or password. '.
- 'Unable to enroll '.$ENV{'form.cuname'}.'.
');
+ }
} else {
$r->print('Invalid username or domain');
}
@@ -660,6 +708,9 @@ sub make_dates_default {
'default_enrollment_end_date' =>$enddate},$dom,$crs);
if ($put_result eq 'ok') {
$result .= "Set default start and end dates for course ";
+ #
+ # Refresh the course environment
+ &Apache::lonnet::coursedescription($ENV{'request.course.id'});
} else {
$result .= "Unable to set default dates for course:".$put_result.
' ';
@@ -667,32 +718,131 @@ sub make_dates_default {
return $result;
}
-# ======================================================= Menu Phase Two Enroll
+##
+## Single student enrollment routines (some of them)
+##
+sub get_student_username_domain_form {
+ my $r = shift;
+ my $domform = &Apache::loncommon::select_dom_form
+ ($ENV{'course.'.$ENV{'request.course.id'}.'.domain'},'cudomain',0);
+ $r->print(<
+
+
Enroll One Student
+
+
Username:
+
+
Domain:
+
$domform
+
+
+
+
+
+END
+ return;
+}
+
sub print_enroll_single_student_form {
my $r=shift;
$r->print("
Enroll One Student
");
- my $today = time;
- my $halfyear = $today+15552000;
- my $defdom=$r->dir_config('lonDefDomain');
- # Set up authentication forms
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($defdom);
- my $javascript_validations=&javascript_validations($krbdefdom);
- my %param = ( formname => 'document.studentform',
- kerb_def_dom => $krbdefdom,
- kerb_def_auth => $krbdef
- );
- my $krbform = &Apache::loncommon::authform_kerberos(%param);
- my $intform = &Apache::loncommon::authform_internal(%param);
- my $locform = &Apache::loncommon::authform_local(%param);
- # Set up domain selection form
- my $domform = &domain_form($defdom);
+ #
+ my $username = $ENV{'form.cuname'};
+ my $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;
+ if ($home ne 'no_host') {
+ $new_user = 0;
+ }
+ #
+ my $user_data_html = '';
+ my $javascript_validations = '';
+ if ($new_user) {
+ my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ # Set up authentication forms
+ my ($krbdef,$krbdefdom) =
+ &Apache::loncommon::get_kerberos_defaults($domain);
+ $javascript_validations=&javascript_validations($krbdefdom);
+ my %param = ( formname => 'document.studentform',
+ kerb_def_dom => $krbdefdom,
+ kerb_def_auth => $krbdef
+ );
+ my $krbform = &Apache::loncommon::authform_kerberos(%param);
+ my $intform = &Apache::loncommon::authform_internal(%param);
+ my $locform = &Apache::loncommon::authform_local(%param);
+ #
+ # Set up domain selection form
+ my $homeserver_form = '';
+ my %servers = &Apache::loncommon::get_library_servers($domain);
+ $homeserver_form = '\n";
+ #
+ #
+ $user_data_html = <User Data for $username\@$domain
+
+
First Name:
+
+
Middle Name:
+
+
Last Name:
+
+
Generation:
+
+
Home Server:
+
$homeserver_form
+
+
Password
+Please select an authentication mechanism
+
+
+$krbform
+
+$intform
+
+$locform
+
+END
+ } else {
+ # User already exists. Do not worry about authentication
+ my %uenv = &Apache::lonnet::dump('environment',$domain,$username);
+ $javascript_validations = &javascript_validations_without_auth();
+ $user_data_html = <User Data for $username\@$domain
+
+
+
First Name:
+
+
+
+
Middle Name:
+
+
+
+
Last Name:
+
+
+
+
Generation:
+
+
+
+
+END
+ }
my $date_table = &date_setting_table();
- # Print it all out
+ # Print it all out
$r->print(<
-
-
+
+
+
+
-
Personal Data
-
-
First Name:
-
Middle Name:
-
Last Name:
-
Generation:
-
-
Login Data
-
Username:
-
Domain: $domform
-
Note: login settings below will not take effect if the user already exists
-
-$krbform
-
-$intform
-
-$locform
-
+$user_data_html
Course Data
@@ -799,7 +932,7 @@ sub print_html_classlist {
-Current Classlist
+Current Class List
END
if ($ENV{'form.action'} ne 'modifystudent') {
@@ -904,7 +1037,7 @@ END
$excel_workbook->set_tempdir('/home/httpd/perl/tmp');
$excel_sheet = $excel_workbook->addworksheet('classlist');
#
- my $description = 'Classlist for '.
+ my $description = 'Class List for '.
$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
$excel_sheet->write($row++,0,$description);
#
@@ -1016,6 +1149,11 @@ sub print_modify_student_form {
}
# determine the students starting and ending times and section
my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
+ if ($starttime =~ /^error/) {
+ $r->print('
Error
');
+ $r->print('
'.$starttime.'
');
+ return;
+ }
# Deal with date forms
my $date_table = &date_setting_table($starttime,$endtime);
#
@@ -1071,6 +1209,9 @@ END
sub modify_single_student {
my $r = shift;
#
+ # 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'}) {
@@ -1212,7 +1353,7 @@ sub get_enrollment_data {
my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
my ($tmp) = keys(%roles);
# Bail out if we were unable to get the students roles
- return "666" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
+ 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 = '';
@@ -1395,6 +1536,7 @@ $upfile_select
+ Ignore First Line
$create_classlist_help
$create_csv_help
@@ -1408,6 +1550,7 @@ sub upfile_drop_add {
my $r=shift;
&Apache::loncommon::load_tmp_file($r);
my @studentdata=&Apache::loncommon::upfile_record_sep();
+ if($ENV{'form.noFirstLine'}){shift(@studentdata);}
my @keyfields = split(/\,/,$ENV{'form.keyfields'});
my $cid = $ENV{'request.course.id'};
my %fields=();
@@ -1456,11 +1599,19 @@ sub upfile_drop_add {
$genpwd=$ENV{'form.locarg'};
}
}
+ if ($amode =~ /^krb/) {
+ if (! defined($genpwd) || $genpwd eq '') {
+ $r->print(''.
+ 'Unable to enroll students:'.' '.
+ 'No Kerberos domain was specified.');
+ $amode = ''; # This causes the loop below to be skipped
+ }
+ }
unless (($domain=~/\W/) || ($amode eq '')) {
#######################################
## Enroll Students ##
#######################################
- $r->print('
Enrolling Students
');
+ $r->print('
Enrolling Students
'."\n".'
');
my $count=0;
my $flushc=0;
my %student=();
@@ -1489,9 +1640,9 @@ sub upfile_drop_add {
}
}
if ($entries{$fields{'username'}}=~/\W/) {
- $r->print('
Unacceptable username: '.
+ $r->print(' Unacceptable username: '.
$entries{$fields{'username'}}.' for user '.
- $fname.' '.$mname.' '.$lname.' '.$gen.'
');
+ $fname.' '.$mname.' '.$lname.' '.$gen.'');
} else {
# determine section number
my $sec='';
@@ -1501,6 +1652,8 @@ 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'})) {
@@ -1509,6 +1662,14 @@ 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) {
@@ -1525,17 +1686,18 @@ sub upfile_drop_add {
\$lname,\$gen,\$sec) {
$$_ =~ s/(\s+$|^\s+)//g;
}
- if ($password) {
+ 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'},$desiredhost);
+ $startdate,$ENV{'form.forceid'},$desiredhost,
+ $email);
if ($reply ne 'ok') {
- $r->print('