--- loncom/interface/Attic/londropadd.pm 2003/06/20 20:57:44 1.68 +++ loncom/interface/Attic/londropadd.pm 2003/07/21 17:54:43 1.76 @@ -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.76 2003/07/21 17:54:43 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -79,13 +79,16 @@ sub modifystudent { # We are in this course my $section=$1; $section='' if ($course eq $courseid.'_st'); - if ( ((!$section) && (!$csec)) || ($section ne $csec) ) { + if ($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 +154,7 @@ sub print_main_menu {

- View Classlist + View Class List

@@ -215,7 +218,7 @@ sub javascript_validations { my $authheader = &Apache::loncommon::authform_header(%param); my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); return (<$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 +708,132 @@ 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 + ($r->dir_config('lonDefDomain'),'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; + } + &Apache::lonnet::logthis('home = '.$home); + # + my $user_data_html = ''; + my $javascript_validations = ''; + if ($new_user) { + my $defdom=$r->dir_config('lonDefDomain'); + # 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 +923,7 @@ sub print_html_classlist {

-Current Classlist +Current Class List       END if ($ENV{'form.action'} ne 'modifystudent') { @@ -904,7 +1028,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); # @@ -1460,7 +1584,7 @@ sub upfile_drop_add { ####################################### ## Enroll Students ## ####################################### - $r->print('

Enrolling Students

'); + $r->print('

Enrolling Students

'."\n".'

'); my $count=0; my $flushc=0; my %student=(); @@ -1489,9 +1613,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=''; @@ -1509,6 +1633,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) { @@ -1531,11 +1663,12 @@ sub upfile_drop_add { 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('

'. - 'Error enrolling '.$username.': '. - $reply.'

'); + $reply =~ s/^error://; + $r->print('
'.$username.':'. + ' Unable to enroll: '.$reply); } else { $count++; $flushc++; $student{$username}=1; @@ -1546,12 +1679,13 @@ sub upfile_drop_add { } } } else { - $r->print("

No password for $username

"); + $r->print('
'.$username.':'. + ' Unable to enroll: No password specified.'); } } } } # end of foreach (@studentdata) - $r->print('

Processed Students: '.$count.'

'); + $r->print('

Processed Students: '.$count.'

'); $r->print("

If active, the new role will be available when the ". "students next log in to LON-CAPA.

"); ##################################### @@ -1627,7 +1761,8 @@ The response to the request is governed upload enrolling enroll students based on upload drop undefined print the classlist ready to drop drop done drop the selected students - enrollstudent undefined print single student enroll menu + 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 @@ -1695,11 +1830,13 @@ sub handler { } } elsif ($ENV{'form.action'} eq 'enrollstudent') { if (! exists($ENV{'form.state'})) { + &get_student_username_domain_form($r); + } elsif ($ENV{'form.state'} eq 'gotusername') { &print_enroll_single_student_form($r); } elsif ($ENV{'form.state'} eq 'enrolling') { &enroll_single_student($r); } else { - &print_enroll_single_student_form($r); + &get_student_username_domain_form($r); } } elsif ($ENV{'form.action'} eq 'classlist') { if (! exists($ENV{'form.state'})) {