+END
+ my ($cdom,$cnum) = split/_/,$ENV{'request.course.id'};
+ if (&Apache::lonnet::auto_run($cnum,$cdom) ) {
+ $r->print(<
+ $Text{'populate'}
+
+END
}
}
-# =============================================== Separate a record into fields
+###############################################################
+###############################################################
+sub hidden_input {
+ my ($name,$value) = @_;
+ return ''."\n";
+}
+
+sub print_upload_manager_header {
+ my ($r,$datatoken,$distotal,$krbdefdom)=@_;
+ my $javascript;
+ #
+ 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=&upload_manager_javascript_forward_associate();
+ }
+ #
+ # 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(''.
+ &mt('Ignore First Line'));
+ $r->print("\n".
+ '');
+}
+
+###############################################################
+###############################################################
+sub javascript_validations {
+ my ($mode,$krbdefdom,$curr_authtype,$curr_authfield)=@_;
+ my $authheader;
+ if ($mode eq 'auth') {
+ my %param = ( formname => '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);
+ }
-sub record_sep {
- my $record=shift;
- my %components=();
- if ($ENV{'form.upfiletype'} eq 'xml') {
- } elsif ($ENV{'form.upfiletype'} eq 'space') {
- my $i=0;
- foreach (split(/\s+/,$record)) {
- my $field=$_;
- $field=~s/^(\"|\')//;
- $field=~s/(\"|\')$//;
- $components{$i}=$field;
- $i++;
- }
- } elsif ($ENV{'form.upfiletype'} eq 'tab') {
- my $i=0;
- foreach (split(/\t+/,$record)) {
- my $field=$_;
- $field=~s/^(\"|\')//;
- $field=~s/(\"|\')$//;
- $components{$i}=$field;
- $i++;
+
+ 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 or group 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 =(<$end) { $notactive=1; }
- }
- unless ($notactive) {
- my $reply=&Apache::lonnet::modifystudent(
- $udom,$unam,'','','',
- '','','','',$section,time);
- }
- }
+ $auth_checks .= (<print(<
-
-
-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.
-
-
Field
Samples
-ENDPICK
- my %sone; my %stwo; my %sthree;
- my $i=0;
-
- if ($total>=0) {
- %sone=&record_sep($records[0]);
- if ($total>=1) {
- %stwo=&record_sep($records[1]);
-
- }
- if ($total>=2) {
- %sthree=&record_sep($records[2]);
- }
- foreach (sort keys %sone) {
- $r->print('
');
- if (defined($sone{$_})) {
- $r->print($sone{$_}."\n");
- }
- if (defined($stwo{$_})) {
- $r->print($stwo{$_}."\n");
- }
- if (defined($sthree{$_})) {
- $r->print($sthree{$_}."\n");
- }
- $r->print('
- 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
+ my $total=$#records;
+ my $distotal=$total+1;
+ my $today=time;
+ my $halfyear=$today+15552000;
+ #
+ # 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 @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,
+ \@field);
+ foreach (@field) {
+ $keyfields.=$_->[0].',';
+ }
+ chop($keyfields);
+ } else {
+ 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)));
+ }
+ }
+ &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
}
-# ======================================================= Enroll single student
-
+###############################################################
+###############################################################
sub enroll_single_student {
my $r=shift;
- $r->print('
Enrolling Student
');
+ # 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('
");
+ #
+ 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('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",
+ );
+ $user_data_html = <$lt{'udf'} $username\@$domain
+
+
$lt{'fn'}:
+
+
$lt{'mn'}:
+
+
$lt{'ln'}:
+
+
$lt{'gen'}:
+
+
$lt{'hs'}:
+
$homeserver_form
+
+
$lt{'pswd'}
+$lt{'psam'}
+
+
+$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",
+ );
+ $user_data_html = <$lt{'udf'} $username\@$domain
+
+
+
$lt{'fn'}:
+
+
+
+
$lt{'mn'}:
+
+
+
+
$lt{'ln'}:
+
+
+
+
$lt{'gen'}:
+
+
+
+
+END
+ }
+ my $date_table = &date_setting_table();
+ # Print it all out
+ my %lt=&Apache::lonlocal::texthash(
+ 'cd' => "Course Data",
+ 'gs' => "Group/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(<
+
+
+
+
+
+$user_data_html
+
+
$lt{'cd'}
+
+
$lt{'gs'}:
+
+$date_table
+
+
$lt{'idsn'}
+
+$lt{'idsn'}:
+
+
+$lt{'disn'}
+
+
+
+END
+ return;
+}
+
+# ========================================================= Menu Phase Two Drop
+sub print_drop_menu {
+ my $r=shift;
+ $r->print("
".&mt('Drop Students')."
");
+ my $cid=$ENV{'request.course.id'};
+ my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print(&mt('There are no students currently enrolled.')."\n");
+ return;
+ }
+ # Print out the available choices
+ &show_drop_list($r,$classlist,$keylist);
+ return;
+}
+
+# ============================================== view classlist
+sub print_html_classlist {
+ my ($r,$mode) = @_;
+ if (! exists($ENV{'form.sortby'})) {
+ $ENV{'form.sortby'} = 'username';
+ }
+ if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
+ $ENV{'form.Status'} = 'Active';
+ }
+ my $status_select = &Apache::lonhtmlcommon::StatusOptions
+ ($ENV{'form.Status'});
+ my $cid=$ENV{'request.course.id'};
+ my $cdom=$ENV{'course.'.$cid.'.domain'};
+ my $cnum=$ENV{'course.'.$cid.'.num'};
+ #
+ # List course personnel
+ my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
+ #
+ if (! defined($ENV{'form.output'}) ||
+ $ENV{'form.output'} !~ /^(csv|excel|html)$/ ) {
+ $ENV{'form.output'} = 'html';
+ }
+ #
+ $r->print('
');
+ foreach my $role (sort keys %coursepersonnel) {
+ next if ($role =~ /^\s*$/);
+ $r->print('
'."\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;
}
- if (foundatype==0) {
- alert('You need to set the login type');
+}
+
+
+#
+# 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.').'