--- loncom/interface/Attic/londropadd.pm 2002/03/06 22:34:06 1.20
+++ loncom/interface/Attic/londropadd.pm 2003/07/28 17:10:12 1.79
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.20 2002/03/06 22:34:06 harris41 Exp $
+# $Id: londropadd.pm,v 1.79 2003/07/28 17:10:12 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,330 +31,359 @@
#
# (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;
-# ================================================================ Print header
-
+###############################################################
+###############################################################
sub header {
- my $r=shift;
- $r->print(<Drop/Add Students
-
+ + Enroll a single student + +
+ + Modify student data + +
+ + View Class List + +
+ + Drop Students + +
+END +} -sub dropstudent { - my ($udom,$unam,$courseid,$csec)=@_; - $courseid=~s/\_/\//g; - $courseid=~s/^(\w)/\/$1/; - foreach (split(/\&/, - &Apache::lonnet::reply('dump:'.$udom.':'.$unam.':roles', - &Apache::lonnet::homeserver($unam,$udom)))) { - my ($key,$value)=split(/\=/,$_); - $key=&Apache::lonnet::unescape($key); - if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) { - my $section=$1; - if ($key eq $courseid.'_st') { $section=''; } - if (((!$section) && (!$csec)) || ($section ne $csec)) { - my ($dummy,$end,$start)=split(/\_/, - &Apache::lonnet::unescape($value)); - my $now=time; - my $notactive=0; - if ($start) { - if ($now<$start) { $notactive=1; } - } - if ($end) { - if ($now>$end) { $notactive=1; } - } - unless ($notactive) { - my $reply=&Apache::lonnet::modifystudent( - $udom,$unam,'','','', - '','','','',$section,time); - } - } +############################################################### +############################################################### +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(); + } + my $javascript_validations=&javascript_validations($krbdefdom); + $r->print(<-
-
-ENDUPFORM
+ if (foundname==0) { message='name fields'; }
+ if (foundid==0) { if (message!='') { message+=', '; } message+='student number field'; }
+ if (foundsec==0) { if (message!='') { message+=', '; } message+='section or group field'; }
+ if (foundemail==0) { if (message!='') { message+=', '; } message+='email address field'; }
+ if (message!='') {
+ message='Not specified (optional): '+message+'. Continue enrollment?';
+ if (confirm(message)) {
+ vf.state.value='enrolling';
+ vf.submit();
+ }
+ } else {
+ vf.state.value='enrolling';
+ vf.submit();
+ }
}
-# ======================================================= Menu Phase Two Upload
-
-sub menu_phase_two_upload {
- my $r=shift;
+$authheader
+ENDPICK
- my $datatoken=&upfile_store($r);
+}
- my @records=&upfile_record_sep();
- my $total=$#records;
- my $distotal=$total+1;
-
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
+sub javascript_validations_without_auth {
+ my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+ return (< Note: this will not take effect if the user already exists
-
-Kerberos authenticated with domain
-
+$krbform
-
-Internally authenticated (with initial password
-)
+$intform
-
-Local Authentication with argument
-
+$locform
+LON-CAPA domain: $domform
+
+$date_table
+
@@ -507,80 +497,363 @@ LON-CAPA domain:
Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
(only do if you know what you are doing)
- Enrolling '.$ENV{'form.cuname'}." \@ ".
+ $ENV{'form.lcdomain'}.' If active, the new role will be available ".
+ "when the student next logs in to LON-CAPA. ERROR ');
+ if ($amode =~ /^krb/) {
+ $r->print('Missing Kerberos domain information. ');
+ } else {
+ $r->print('Invalid login mode or password. ');
+ }
+ $r->print('Unable to enroll '.$ENV{'form.cuname'}.'.
+$krbform
+ Group/Section:
+
+$date_table
+
+ID/Student Number:
+
+
+Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
+(only do if you know what you are doing)
+
+
+
+Current Class List
+
+END
+ if ($ENV{'form.action'} ne 'modifystudent') {
+ $r->print(<
+ '.
+ 'Your Excel spreadsheet is ready for download.
-
-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
-)
+
+#
+# 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('Error'.
+ ' '.
+ 'Unable to retrieve environment data for '.$sname.
+ 'in domain '.$sdom.' '.
+ 'Please contact your LON-CAPA administrator '.
+ 'regarding this situation.
-Identify fields
-Total number of records found in file: $distotal
-
-
+}
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('Field Samples ');
- $i++;
- }
- $i--;
- }
- my $keyfields=join(',',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(' Login Type
LON-CAPA Domain for Students
-LON-CAPA domain: Starting and Ending Dates
-
-
-
-
-
-Set Starting DateFull Update
Full update
(also print list of users not enrolled anymore)
-Note: for large courses, this operation might be time consuming.
+
+Note: for large courses, this operation may be time consuming.
ENDPICK
}
-# ======================================================= Enroll single student
+# ======================================================= Menu Phase Two Upload
+sub print_upload_manager_form {
+ my $r=shift;
+ my $datatoken;
+ if (!$ENV{'form.datatoken'}) {
+ $datatoken=&Apache::loncommon::upfile_store($r);
+ } else {
+ $datatoken=$ENV{'form.datatoken'};
+ &Apache::loncommon::load_tmp_file($r);
+ }
+ my @records=&Apache::loncommon::upfile_record_sep();
+ my $total=$#records;
+ my $distotal=$total+1;
+ my $today=time;
+ my $halfyear=$today+15552000;
+ my $defdom=$r->dir_config('lonDefDomain');
+ 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'],
+ ['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);
+ foreach (@d) { $keyfields.=$_->[0].','; }
+ chop($keyfields);
+ } else {
+ unshift(@d,['none','']);
+ $i=&Apache::loncommon::csv_samples_select_table($r,\@records,\@d);
+ 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;
+ # Remove whitespace from section
+ $ENV{'form.csec'}=~s/(\s|:)//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
+ # 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('Enrolling Student
');
+ $r->print('\n";
+ $result .= '
\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 \n";
+ $result .= 'Starting Date '.
+ ''.$startform.' '.
+ ''.$dateDefault.' '." \n";
+ $result .= "Ending Date '.
+ ''.$endform.' '.
+ ''.$perpetual.' '."
";
+ #
+ # Refresh the course environment
+ &Apache::lonnet::coursedescription($ENV{'request.course.id'});
+ } else {
+ $result .= "Unable to set default dates for course:".$put_result.
+ '
';
+ }
+ return $result;
+}
- my $defdom=$r->dir_config('lonDefDomain');
+##
+## 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
+
+
+END
+ return;
+}
- $r->print(<
+Username:
+
+Domain:
+ $domform
+
+
+
+ Enroll One Student
");
+ #
+ 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 = <
+
+
+First Name:
+
+Middle Name:
+
+Last Name:
+
+Generation:
+
+Home Server:
+ $homeserver_form Password
+Please select an authentication mechanism
+
+
+$intform
+
+$locform
+
+
+END
+ }
+ my $date_table = &date_setting_table();
+ # Print it all out
+ $r->print(<
+First Name:
+
+
+
+Middle Name:
+
+
+
+Last Name:
+
+
+
+Generation:
+
+
+ Course Data
-function clickloc(vf) {
- vf.krbdom.value='';
- vf.intpwd.value='';
+ID/Student Number
+Drop Students
");
+ my $cid=$ENV{'request.course.id'};
+ my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print("There are no students currently enrolled.\n");
+ return;
}
+ # Print out the available choices
+ &show_drop_list($r,$classlist,$keylist);
+ return;
+}
- function pjump(type,dis,value,marker,ret,call) {
- parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
- +"&value="+escape(value)+"&marker="+escape(marker)
- +"&return="+escape(ret)
- +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
- "height=350,width=350,scrollbars=no,menubar=no");
+# ============================================== view classlist
+sub print_html_classlist {
+ my $r=shift;
+ 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'},'studentform');
+ $r->print(<
+
+END
+ } elsif ($mode eq 'csv') {
+ if($statusmode eq 'Expired') {
+ $r->print('"Students with expired roles"');
}
- if (document.studentform.pres_marker.value=='start') {
- document.studentform.startdate.value=
- document.studentform.pres_value.value;
+ if ($statusmode eq 'Any') {
+ $r->print('"'.join('","',("username","domain","ID","student name",
+ "section","status")).'"'."\n");
+ } else {
+ $r->print('"'.join('","',("username","domain","ID","student name",
+ "section")).'"'."\n");
}
- pclose();
+ } elsif ($mode eq 'excel') {
+ # Create the excel spreadsheet
+ $excel_filename = '/prtspool/'.
+ $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
+ time.'_'.rand(1000000000).'.xls';
+ $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
+ $excel_filename);
+ $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
+ $excel_sheet = $excel_workbook->addworksheet('classlist');
+ #
+ my $description = 'Class List for '.
+ $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
+ $excel_sheet->write($row++,0,$description);
+ #
+ $excel_sheet->write($row++,0,["username","domain","ID",
+ "student name","section","status"]);
+ }
+ #
+ # Sort the students
+ my %index;
+ my $i;
+ foreach (@$keylist) {
+ $index{$_} = $i++;
+ }
+ my $index = $index{$sortby};
+ my $second = $index{'username'};
+ my $third = $index{'domain'};
+ my @Sorted_Students = sort {
+ lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
+ ||
+ lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
+ ||
+ lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
+ } (keys(%$classlist));
+ foreach my $student (@Sorted_Students) {
+ my $username = $classlist->{$student}->[$index{'username'}];
+ my $domain = $classlist->{$student}->[$index{'domain'}];
+ my $section = $classlist->{$student}->[$index{'section'}];
+ my $name = $classlist->{$student}->[$index{'fullname'}];
+ my $id = $classlist->{$student}->[$index{'id'}];
+ my $status = $classlist->{$student}->[$index{'status'}];
+ next if (($statusmode ne 'Any') && ($status ne $statusmode));
+ if ($mode eq 'view') {
+ $r->print("
+ username
+
+ domain
+
+ ID
+
+ student name
+
+ section
+
+\n
+END
+ } elsif ($mode eq 'csv') {
+ # no need to bother with $linkto
+ my @line = ();
+ foreach ($username,$domain,$id,$name,$section) {
+ push @line,&Apache::loncommon::csv_translate($_);
+ }
+ if ($statusmode eq 'Any') {
+ push @line,&Apache::loncommon::csv_translate($status);
+ }
+ my $tmp = $";
+ $" = '","';
+ $r->print("\"@line\"\n");
+ $" = $tmp;
+ } elsif ($mode eq 'excel') {
+ $excel_sheet->write($row++,0,[$username,$domain,$id,
+ $name,$section,$status]);
+ }
+ }
+ if ($mode eq 'view') {
+ $r->print('\n ");
+ if ($linkto eq 'nothing') {
+ $r->print($username);
+ } elsif ($linkto eq 'aboutme') {
+ $r->print(&Apache::loncommon::aboutmewrapper($username,
+ $username,
+ $domain));
+ } elsif ($linkto eq 'modify') {
+ $r->print(''.
+ $username."\n");
+ }
+ $r->print(<<"END");
+
+ $domain
+ $id
+ $name
+ $section
+
');
+ } elsif ($mode eq 'excel') {
+ $excel_workbook->close();
+ $r->print('Personal Data
-First Name:
-Middle Name:
-Last Name:
-Generation: Login Data
-Username: