--- loncom/interface/Attic/londropadd.pm 2002/01/04 18:13:58 1.19
+++ loncom/interface/Attic/londropadd.pm 2003/07/05 10:07:11 1.73
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.19 2002/01/04 18:13:58 www Exp $
+# $Id: londropadd.pm,v 1.73 2003/07/05 10:07:11 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,329 +31,329 @@
#
# (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 Classlist + +
+ + Drop Students + +
+END } -# ============================================================== Menu Phase One - -sub menu_phase_one { - my $r=shift; - $r->print(<-
+###############################################################
+###############################################################
+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
+ 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
+
@@ -506,80 +467,257 @@ 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 '.
+ 'Invalid login mode or password. '.
+ 'Unable to enroll '.$ENV{'form.cuname'}.'. Username: Domain: $domform Note: login settings below will not take effect if the user already exists
+
+$krbform
+
+$intform
+
+$locform
+
-function clickint(vf) {
- vf.krbdom.value='';
- vf.locarg.value='';
-}
+ 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 Classlist
+
+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.
-Drop students
-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
}
-# ======================================================= Menu Phase Two Upload
-
-sub menu_phase_two_upload {
- my $r=shift;
-
- my $datatoken=&upfile_store($r);
+###############################################################
+###############################################################
+sub javascript_validations {
+ my ($krbdefdom)=@_;
+ my %param = ( formname => 'studentform',
+ kerb_def_dom => $krbdefdom );
+ my $authheader = &Apache::loncommon::authform_header(%param);
+ my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+ return (<
-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]);
- }
- map {
- $r->print('Field Samples ');
- $i++;
- } sort keys %sone;
- $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;
+ #
+ # 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;
+}
-sub menu_phase_two_enroll {
+# ======================================================= Menu Phase Two Enroll
+sub print_enroll_single_student_form {
my $r=shift;
-
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
-
- my $today=time;
- my $halfyear=$today+15552000;
-
+ $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 $date_table = &date_setting_table();
+ # Print it all out
+ $r->print(<Personal Data
+
+
-function clickkrb(vf) {
- vf.krbdom.value='$krbdefdom';
- vf.intpwd.value='';
- vf.locarg.value='';
-}
+
+First Name:
+Middle Name:
+Last Name:
+Generation: Login Data
+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 ($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");
}
- if (document.studentform.pres_marker.value=='start') {
- document.studentform.startdate.value=
- document.studentform.pres_value.value;
+ } 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 = 'Classlist 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]);
}
- pclose();
}
+ 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: