--- loncom/interface/Attic/londropadd.pm 2001/09/25 18:12:43 1.16
+++ loncom/interface/Attic/londropadd.pm 2003/09/29 16:09:20 1.86
@@ -1,332 +1,392 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# (Handler to set parameters for assessments
+# $Id: londropadd.pm,v 1.86 2003/09/29 16:09:20 www Exp $
#
-# (Handler to resolve ambiguous file locations
+# Copyright Michigan State University Board of Trustees
#
-# (TeX Content Handler
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+#
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
#
-# YEAR=2000
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# 10/11,10/12,10/16 Gerd Kortemeyer)
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
-# 12/08,12/12 Gerd Kortemeyer)
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
+# (Handler to set parameters for assessments
#
-# 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
+# (Handler to resolve ambiguous file locations
+#
+# (TeX Content Handler
+#
+###############################################################
+##############################################################
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::lonlocal;
-# ================================================================ 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/; - map { - 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'; } - } split(/\&/,&Apache::lonnet::reply('dump:'.$udom.':'.$unam.':roles', - &Apache::lonnet::homeserver($unam,$udom))); + } + 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); + my $checked=(($ENV{'form.noFirstLine'})?' checked="1"':''); + $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
+
-
+ 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]);
- }
- 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.
+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 may be time consuming.
ENDPICK
}
-# ======================================================= Enroll single student
+# ======================================================= Menu Phase Two Upload
+sub print_upload_manager_form {
+ my $r=shift;
+ my $firstLine;
+ 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();
+ if($ENV{'form.noFirstLine'}){$firstLine=shift(@records);}
+ my $total=$#records;
+ my $distotal=$total+1;
+ my $today=time;
+ my $halfyear=$today+15552000;
+ 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'],
+ ['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 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 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
+ ($ENV{'course.'.$ENV{'request.course.id'}.'.domain'},'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=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ # 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 ($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 = '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]);
}
- 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: