--- loncom/interface/Attic/londropadd.pm 2002/04/16 21:02:17 1.26 +++ loncom/interface/Attic/londropadd.pm 2006/07/20 21:55:37 1.146 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to drop and add students in courses # -# $Id: londropadd.pm,v 1.26 2002/04/16 21:02:17 matthew Exp $ +# $Id: londropadd.pm,v 1.146 2006/07/20 21:55:37 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,58 +25,38 @@ # # 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; +use Apache::longroup; -# ================================================================ Print header - +############################################################### +############################################################### sub header { - my $r=shift; - $r->print(< - -LON-CAPA Student Drop/Add - - - -

Drop/Add Students

-
-

Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}

+ my $start_page=&Apache::loncommon::start_page('Enrollment Manager'); + return(< 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 { - my ($udom,$unam,$courseid,$csec)=@_; + my ($udom,$unam,$courseid,$csec,$desiredhost)=@_; # 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 course and add them to section $csec @@ -85,216 +65,402 @@ sub modifystudent { my %roles = &Apache::lonnet::dump('roles',$udom,$unam); my ($tmp) = keys(%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 + my $result = ''; foreach my $course (keys(%roles)) { - my $value = $roles{$course}; - if ($course=~/^$courseid(?:\/)*(\w+)*\_st$/) { + if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) { # We are in this course my $section=$1; $section='' if ($course eq $courseid.'_st'); - if (((!$section) && (!$csec)) || ($section ne $csec)) { - my (undef,$end,$start)=split(/\_/,$course); + 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 (($start) && ($end) && ($now>$start) && ($now<$end)) { + # if this is an active role + if (!($start && ($now<$start)) || !($end && ($now>$end))) { my $reply=&Apache::lonnet::modifystudent - ($udom,$unam,'','','','','','','',$section,time); + # dom name id mode pass f m l g + ($udom,$unam,'', '', '',undef,undef,undef,undef, + $section,time,undef,undef,$desiredhost); + $result .= $reply.':'; } } } } + if ($result eq '') { + $result = 'Unable to find section for this student'; + } else { + $result =~ s/(ok:)+/ok/g; + } + return $result; } -# ============================================================== Menu Phase One -sub menu_phase_one { - my $r=shift; - my $upfile_select=&Apache::loncommon::upfile_select_html(); - $r->print(< -
-

Upload a courselist

-$upfile_select -

-


-

Enroll a single student

-

-


-

Drop students

-

-ENDUPFORM +############################################################### +############################################################### +# build a domain and server selection form +sub domain_form { + my ($defdom) = @_; + # Set up domain and server selection forms + # + # Get the domains + my @domains = &Apache::loncommon::get_domains(); + # build up the menu information to be passed to + # &Apache::loncommon::linked_select_forms + my %select_menus; + foreach my $dom (@domains) { + # set up the text for this domain + $select_menus{$dom}->{'text'}= $dom; + # we want a choice of 'default' as the default in the second menu + $select_menus{$dom}->{'default'}= 'default'; + $select_menus{$dom}->{'select2'}->{'default'} = 'default'; + # Now build up the other items in the second menu + my %servers = &Apache::loncommon::get_library_servers($dom); + foreach my $server (keys(%servers)) { + $select_menus{$dom}->{'select2'}->{$server} + = "$server $servers{$server}"; + } + } + my $result = &Apache::loncommon::linked_select_forms + ('studentform',' with home server ',$defdom, + 'lcdomain','lcserver',\%select_menus); + return $result; } -sub phase_two_header { +############################################################### +############################################################### +# Menu Phase One +sub print_main_menu { + my ($r,$enrl_permission,$view_permission,$grp_manage_permission, + $grp_view_permission)=@_; + # + my ($cdom,$cnum) = split/_/,$env{'request.course.id'}; + my @menu = + ( + { text => 'Upload a class list', + help => 'Course_Create_Class_List', + action => 'upload', + permission => $enrl_permission, + }, + { text => 'Enroll a single student', + help => 'Course_Add_Student', + action => 'enrollstudent', + permission => $enrl_permission, + }, + { text => 'Modify student data', + help => 'Course_Modify_Student_Data', + action => 'modifystudent', + permission => $enrl_permission, + }, + { text => 'View Class List', + help => 'Course_View_Class_List', + action => 'classlist', + permission => $view_permission, + }, + { text => 'Drop Students', + help => 'Course_Drop_Student', + action => 'drop', + permission => $enrl_permission, + }, + { text => 'Automated Enrollment Manager', + permission => &Apache::lonnet::auto_run($cnum,$cdom), + url => '/adm/populate', + }, + { text => 'Create a new group', + help => 'Course_Create_Group', + permission => $grp_manage_permission, + url => '/adm/coursegroups?refpage=enrl&action=create', + }, + { text => 'Modify an existing group', + help => 'Course_Modify_Group', + permission => $grp_manage_permission, + url => '/adm/coursegroups?refpage=enrl&action=modify', + }, +# { text => 'Delete an existing group', +# help => 'Course_Delete_Group', +# permission => $grp_manage_permission, +# url => '/adm/coursegroups?refpage=enrl&action=delete', +# }, + { text => 'Enter an existing group', + help => 'Course_Display_Group', + permission => $grp_view_permission, + url => '/adm/coursegroups?refpage=enrl&action=view', + }, + ); + my $menu_html = ''; + foreach my $menu_item (@menu) { + next if (! $menu_item->{'permission'}); + $menu_html.='

'; + $menu_html.=''; + if (exists($menu_item->{'url'})) { + $menu_html.=qq{}; + } else { + $menu_html.= + qq{}; + } + $menu_html.= &mt($menu_item->{'text'}).''; + if (exists($menu_item->{'help'})) { + $menu_html.= + &Apache::loncommon::help_open_topic($menu_item->{'help'}); + } + $menu_html.='

'.$/; + } + $r->print($menu_html); + return; +} + +############################################################### +############################################################### +sub hidden_input { + my ($name,$value) = @_; + return ''."\n"; +} + +sub print_upload_manager_header { my ($r,$datatoken,$distotal,$krbdefdom)=@_; my $javascript; - if ($ENV{'form.upfile_associate'} eq 'reverse') { - $javascript=&phase_two_javascript_reverse_associate(); + # + if (! exists($env{'form.upfile_associate'})) { + $env{'form.upfile_associate'} = 'forward'; + } + if ($env{'form.associate'} eq 'Reverse Association') { + if ( $env{'form.upfile_associate'} ne 'reverse' ) { + $env{'form.upfile_associate'} = 'reverse'; + } else { + $env{'form.upfile_associate'} = 'forward'; + } + } + if ($env{'form.upfile_associate'} eq 'reverse') { + $javascript=&upload_manager_javascript_reverse_associate(); } else { - $javascript=&phase_two_javascript_forward_associate(); + $javascript=&upload_manager_javascript_forward_associate(); } - my $javascript_validations=&javascript_validations($krbdefdom); - $r->print(< -

Identify fields

-Total number of records found in file: $distotal
-Enter as many fields as you can. The system will inform you and bring you back -to this page if the data selected is insufficient to run your class.
- - - - - - -
- -ENDPICK + # + # Deal with restored settings + my $password_choice = ''; + if (exists($env{'form.ipwd_choice'}) && + $env{'form.ipwd_choice'} ne '') { + # If a column was specified for password, assume it is for an + # internal password. This is a bug waiting to be filed (could be + # local or krb auth instead of internal) but I do not have the + # time to mess around with this now. + $password_choice = 'int'; + } + # + my $javascript_validations=&javascript_validations('auth',$krbdefdom, + $password_choice); + my $checked=(($env{'form.noFirstLine'})?' checked="1"':''); + $r->print('

'.&mt('Uploading Class List')."

\n". + "
\n". + '

'.&mt('Identify fields')."

\n"); + $r->print("

\n". + &mt('Total number of records found in file: [_1].',$distotal). + "\n". + "


\n"); + $r->print(&mt('Enter as many fields as you can. The system will inform you and bring you back to this page if the data selected is insufficient to enroll students in your class.')."
\n"); + $r->print(&hidden_input('action','upload'). + &hidden_input('state','got_file'). + &hidden_input('associate',''). + &hidden_input('datatoken',$datatoken). + &hidden_input('fileupload',$env{'form.fileupload'}). + &hidden_input('upfiletype',$env{'form.upfiletype'}). + &hidden_input('upfile_associate',$env{'form.upfile_associate'})); + $r->print(''); + $r->print(''); + $r->print("
\n". + ''); } +############################################################### +############################################################### sub javascript_validations { - my ($krbdefdom)=@_; - return (< 'studentform', + kerb_def_dom => $krbdefdom, + curr_authtype => $curr_authtype); + $authheader = &Apache::loncommon::authform_header(%param); + } elsif ($mode eq 'createcourse') { + my %param = ( formname => 'ccrs', + kerb_def_dom => $krbdefdom, + curr_authtype => $curr_authtype ); + $authheader = &Apache::loncommon::authform_header(%param); + } elsif ($mode eq 'modifycourse') { + my %param = ( formname => 'cmod', + kerb_def_dom => $krbdefdom, + mode => 'modifycourse', + curr_authtype => $curr_authtype, + curr_autharg => $curr_authfield ); + $authheader = &Apache::loncommon::authform_header(%param); + } + + + my %alert = &Apache::lonlocal::texthash + (username => 'You need to specify the username field.', + authen => 'You must choose an authentication type.', + krb => 'You need to specify the Kerberos domain.', + ipass => 'You need to specify the initial password.', + name => 'The optional name field was not specified.', + snum => 'The optional student number field was not specified.', + section => 'The optional section field was not specified.', + email => 'The optional email address field was not specified.', + continue => 'Continue enrollment?', + ); + +# my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); + my $function_name =(<=3) && @@ -328,6 +511,8 @@ function flip(vf,tf) { } } } + // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6), + // clear out any that are set to 'lastname, firstnames' (2) if ((nw>=3) && (nw<=6)) { for (i=0;i<=vf.nfields.value;i++) { if (eval('vf.f'+i+'.selectedIndex')==2) { @@ -335,10 +520,13 @@ function flip(vf,tf) { } } } + // If we set the password, make the password form below correspond to + // the new value. if (nw==9) { - vf.login[1].checked=true; - vf.intpwd.value=''; - vf.krbdom.value=''; + changed_radio('int',document.studentform); + set_auth_radio_buttons('int',document.studentform); + vf.intarg.value=''; + vf.krbarg.value=''; vf.locarg.value=''; } } @@ -355,9 +543,11 @@ function clearpwd(vf) { ENDPICK } -sub phase_two_javascript_reverse_associate { +############################################################### +############################################################### +sub upload_manager_javascript_reverse_associate { return(<print(< - - -

Login Type

-

Note: this will not take effect if the user already exists

-

- -Kerberos authenticated with domain - -

-

- -Internally authenticated (with initial password -) -

-

- -Local Authentication with argument - -

-

LON-CAPA Domain for Students

-LON-CAPA domain:

-

Starting and Ending Dates

- - - - - -Set Starting Date

- -Set Ending Date

-

Full Update

- Full update -(also print list of users not enrolled anymore)

-

ID/Student Number

- -Disable ID/Student Number Safeguard and Force Change of Conflicting IDs -(only do if you know what you are doing)

-
-Note: for large courses, this operation might be time consuming. -ENDPICK -} -# ======================================================= Menu Phase Two Upload -sub menu_phase_two_upload { + my ($krbdef,$krbdefdom) = + &Apache::loncommon::get_kerberos_defaults($defdom); + my %param = ( formname => 'document.studentform', + kerb_def_dom => $krbdefdom, + kerb_def_auth => $krbdef + ); + if (exists($env{'form.ipwd_choice'}) && + defined($env{'form.ipwd_choice'}) && + $env{'form.ipwd_choice'} ne '') { + $param{'curr_authtype'} = 'int'; + } + my $krbform = &Apache::loncommon::authform_kerberos(%param); + my $intform = &Apache::loncommon::authform_internal(%param); + my $locform = &Apache::loncommon::authform_local(%param); + my $domform = &domain_form($defdom); + my $date_table = &date_setting_table(); + my $Str = "\n"; + $Str .= &hidden_input('nfields',$i); + $Str .= &hidden_input('keyfields',$keyfields); + $Str .= '

'.&mt('Login Type')."

\n"; + $Str .= "

\n". + &mt('Note: this will not take effect if the user already exists'). + &Apache::loncommon::help_open_topic('Auth_Options'). + "

\n"; + $Str .= $krbform."\n

\n". + $intform."\n

\n". + $locform."\n

\n"; + $Str .= '

'.&mt('LON-CAPA Domain for Students')."

\n"; + $Str .= "

\n".&mt('LON-CAPA domain: [_1]',$domform)."\n

\n"; + $Str .= "

".&mt('Starting and Ending Dates')."

\n"; + $Str .= "

\n".$date_table."

\n"; + $Str .= "

".&mt('Full Update')."

\n"; + $Str .= '

\n"; + $Str .= "

".&mt('Student Number')."

\n"; + $Str .= "

\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'}) { - $datatoken=&Apache::loncommon::upfile_store($r); + if (!$env{'form.datatoken'}) { + $datatoken=&Apache::loncommon::upfile_store($r); } else { - $datatoken=$ENV{'form.datatoken'}; - &Apache::loncommon::load_tmp_file($r); + $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('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('

Enrolling Student

'); - if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&& - ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) { + # 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 separate from the action of enrolling the + # student. Also, a failure in setting the dates as default is not fatal + # to the process of enrolling / modifying a student. + my ($startdate,$enddate) = &get_dates_from_form(); + if ($env{'form.makedatesdefault'}) { + $r->print(&make_dates_default($startdate,$enddate)); + } + + $r->print('

'.&mt('Enrolling Student').'

'); + $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') { + 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.intpwd'}; - } elsif ($ENV{'form.login'} eq 'loc') { + $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)) { - &modifystudent($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('Invalid username or domain'); + $r->print(&mt('Invalid username or domain')); } } -# ======================================================= Menu Phase Two Enroll -sub menu_phase_two_enroll { +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 = ''. + ''; + if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') { + $dateDefault = ' '; + } + my $perpetual = ''; + if ($mode eq 'create_enrolldates') { + $perpetual = ' '; + } + my $result = ''; + $result .= "\n"; + $result .= ''. + ''. + ''."\n"; + $result .= ''. + ''. + ''."\n"; + $result .= "
'.&mt('Starting Date').''.$startform.''.$dateDefault.'
'.&mt('Ending Date').''.$endform.''.$perpetual.'
\n"; + return $result; +} + +sub make_dates_default { + my ($startdate,$enddate) = @_; + my $result = ''; + my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $put_result = &Apache::lonnet::put('environment', + {'default_enrollment_start_date'=>$startdate, + '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'}, + {'freshen_cache' => 1}); + } else { + $result .= &mt('Unable to set default dates for course').":".$put_result. + '
'; + } + return $result; +} + +## +## 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); + my %lt=&Apache::lonlocal::texthash( + 'eos' => "Enroll One Student", + 'usr' => "Username", + 'dom' => "Domain", + 'been' => "Begin Enrollment", + ); + $r->print(< + +

$lt{'eos'}

+ + + + + + + +
$lt{'usr'}:
$lt{'dom'}:$domform
  + +
+ +END + return; +} + +sub print_enroll_single_student_form { my $r=shift; - my ($krbdefdom) = $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/; - $krbdefdom=~tr/a-z/A-Z/; - my $today = time; - my $halfyear = $today+15552000; - my $defdom=$r->dir_config('lonDefDomain'); - my $javascript_validations=&javascript_validations($krbdefdom); - $r->print(< -function verify(vf) { + $r->print("

".&mt('Enroll One Student')."

"); + # + my $username = $env{'form.cuname'}; + my $domain = $env{'form.cudomain'}; + $username=~s/\W//gs; + $domain=~s/\W//gs; + 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('auth',$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"; + # + # + my %lt=&Apache::lonlocal::texthash( + 'udf' => "User Data for", + 'fn' => "First Name", + 'mn' => "Middle Name", + 'ln' => "Last Name", + 'gen' => "Generation", + 'hs' => "Home Server", + 'pswd' => "Password", + 'psam' => "Please select an authentication mechanism", + 'mail' => "Email Address" + ); + my $authhelp=&Apache::loncommon::help_open_topic('Auth_Options'); + $user_data_html = <$lt{'udf'} $username\@$domain + + + + + + + + + + + + + +
$lt{'fn'}:
$lt{'mn'}:
$lt{'ln'}:
$lt{'gen'}:
$lt{'hs'}:$homeserver_form
$lt{'mail'}:
+

$lt{'pswd'}

+$lt{'psam'}$authhelp + +

+$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('noauth'); + my %lt=&Apache::lonlocal::texthash( + 'udf' => "User Data for", + 'fn' => "First Name", + 'mn' => "Middle Name", + 'ln' => "Last Name", + 'gen' => "Generation", + 'mail' => "Email Address", + ); + $user_data_html = <$lt{'udf'} $username\@$domain + +
+ + + + + + + + + + +
$lt{'fn'}: + +
$lt{'mn'}: + +
$lt{'ln'}: + +
$lt{'gen'}: + +
$lt{'mail'}: + +
+END + } + my $date_table = &date_setting_table(); + # Print it all out + my %lt=&Apache::lonlocal::texthash( + 'cd' => "Course Data", + 'gs' => "Section", + 'idsn' => "ID/Student Number", + 'disn' => "Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)", + 'eas' => "Enroll as student", + ); + $r->print(< + + + + -

Personal Data

-First Name:
-Middle Name:
-Last Name:
-Generation: - -

ID/Student Number:

- -

Group/Section:

- -

Login Data

-

Username:

-

Domain:

-

Note: login settings below will not take effect if the user already exists -

- -Kerberos authenticated with domain - -

- -Internally authenticated (with initial password -) -

- -Local Authentication with argument - -

-

Starting and Ending Dates

- - - - - -

-Set Starting Date -

-Set Ending Date + +$user_data_html + +

$lt{'cd'}

+ +

$lt{'gs'}: +

+$date_table +

+

$lt{'idsn'}

+

+$lt{'idsn'}:

-

ID/Student Number

+