--- loncom/interface/Attic/londropadd.pm 2001/02/14 12:29:25 1.11
+++ loncom/interface/Attic/londropadd.pm 2003/11/06 20:04:06 1.88
@@ -1,322 +1,403 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# (Handler to set parameters for assessments
+# $Id: londropadd.pm,v 1.88 2003/11/06 20:04:06 matthew 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.
+#
+# 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.
+#
+# 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
#
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
+# /home/httpd/html/adm/gpl.txt
#
-# 10/11,10/12,10/16 Gerd Kortemeyer)
+# http://www.lon-capa.org/
#
-# 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
-# 12/08,12/12 Gerd Kortemeyer)
+# (Handler to set parameters for assessments
+#
+# (Handler to resolve ambiguous file locations
#
-# 12/26,12/27,12/28,
-# 01/01/01,01/15,02/10,02/13,02/14 Gerd Kortemeyer
+# (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(<
-LON-CAPA Student Drop/Add
+$title
-
-
-
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
}
-# ======================================================= Menu Phase Two Enroll
-
-sub menu_phase_two_enroll {
+# ======================================================= Menu Phase Two Upload
+sub print_upload_manager_form {
my $r=shift;
-
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
-
+ 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);
+}
- my $defdom=$r->dir_config('lonDefDomain');
+# ======================================================= 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(<Personal Data
+ $r->print('
+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);
+}
-Group/Section:
+sub date_setting_table {
+ my ($starttime,$endtime) = @_;
+ my ($startform,$endform)=&setup_date_selectors($starttime,$endtime);
+ my $dateDefault = ''.
+ ''.
+ ' make these dates the default for future enrollment';
+ my $perpetual = ''.' no ending date';
+ my $result = '';
+ $result .= "
\n";
+ $result .= '
Starting Date
'.
+ '
'.$startform.'
'.
+ '
'.$dateDefault.'
'."
\n";
+ $result .= '
Ending Date
'.
+ '
'.$endform.'
'.
+ '
'.$perpetual.'
'."
\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 ";
+ #
+ # Refresh the course environment
+ &Apache::lonnet::coursedescription($ENV{'request.course.id'});
+ } else {
+ $result .= "Unable to set default dates for course:".$put_result.
+ ' ';
+ }
+ return $result;
+}
-Initial password (if applicable):
+##
+## 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(<
+
+
-ENDSENROLL
+sub print_enroll_single_student_form {
+ my $r=shift;
+ $r->print("
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;
+ }
+ #
+ 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 = <User Data for $username\@$domain
+
+
First Name:
+
+
Middle Name:
+
+
Last Name:
+
+
Generation:
+
+
Home Server:
+
$homeserver_form
+
+
Password
+Please select an authentication mechanism
+
+
+$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_without_auth();
+ $user_data_html = <User Data for $username\@$domain
+
+
+
First Name:
+
+
+
+
Middle Name:
+
+
+
+
Last Name:
+
+
+
+
Generation:
+
+
+
+
+END
+ }
+ my $date_table = &date_setting_table();
+ # Print it all out
+ $r->print(<
+
+
+
+
+
+$user_data_html
+
+
Course Data
+
+
Group/Section:
+
+$date_table
+
+
ID/Student Number
+
+ID/Student Number:
+
+
+Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
+(only do if you know what you are doing)
+
+
+
+END
+ return;
}
# ========================================================= Menu Phase Two Drop
+sub print_drop_menu {
+ my $r=shift;
+ $r->print("
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;
+}
-sub menu_phase_two_drop {
+# ============================================== 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(<
+
+
+Current Class List
+
+END
+ if ($ENV{'form.action'} ne 'modifystudent') {
+ $r->print(<
+CSV format
+
+Excel format
+
+
+Student Status:
+END
+ }
+ $r->print($status_select."
\n");
my $cid=$ENV{'request.course.id'};
- my $classlst=&Apache::lonnet::reply
- ('dump:'.$ENV{'course.'.$cid.'.domain'}.':'.
- $ENV{'course.'.$cid.'.num'}.':classlist',
- $ENV{'course.'.$cid.'.home'});
- my %currentlist=();
- my $now=time;
- unless ($classlst=~/^error\:/) {
- map {
- my ($name,$value)=split(/\=/,$_);
- my ($end,$start)=split(/\:/,
- &Apache::lonnet::unescape($value));
- my $active=1;
- if (($end) && ($now>$end)) { $active=0; }
- if ($active) {
- $currentlist{&Apache::lonnet::unescape($name)}=1;
- }
- } split(/\&/,$classlst);
-# ----------------------------------------------------------- Print out choices
- &show_drop_list($r,%currentlist);
- } else {
- $r->print(
- '
Could not access classlist: '.$classlst.
- '
');
- }
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print("There are no students currently enrolled.\n");
+ } else {
+ # Print out the available choices
+ if ($ENV{'form.action'} eq 'modifystudent') {
+ &show_class_list($r,'view','modify','modifystudent',
+ $ENV{'form.Status'},$classlist,$keylist);
+ } else {
+ &show_class_list($r,'view','aboutme','classlist',
+ $ENV{'form.Status'},$classlist,$keylist);
+ }
+ }
}
-# =================================================== Show student list to drop
+# ============================================== view classlist
+sub print_formatted_classlist {
+ my $r=shift;
+ my $mode = shift;
+ 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");
+ } else {
+ &show_class_list($r,$mode,'nolink','csv',
+ $ENV{'form.Status'},$classlist,$keylist);
+ }
+}
-sub show_drop_list {
- my ($r,%currentlist)=@_;
+# =================================================== Show student list to drop
+sub show_class_list {
+ my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
my $cid=$ENV{'request.course.id'};
+ #
+ # Variables for excel output
+ my ($excel_workbook, $excel_sheet, $excel_filename,$row);
+ #
+ my $sortby = $ENV{'form.sortby'};
+ if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
+ $sortby = 'username';
+ }
+ # Print out header
+ if ($mode eq 'view') {
+ if ($linkto eq 'aboutme') {
+ $r->print('Select a user name to view the users personal page.');
+ } elsif ($linkto eq 'modify') {
+ $r->print('Select a user name to modify the students information');
+ }
+ $r->print(<print('');
- $r->print('
');
- map {
- my ($sname,$sdom)=split(/\:/,$_);
- my %reply=&Apache::lonnet::idrget($sdom,$sname);
- my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
- my @reply=split(/[\&\=]/,&Apache::lonnet::reply(
- 'get:'.$sdom.':'.$sname.
- ':environment:firstname&middlename&lastname&generation',
- &Apache::lonnet::homeserver($sname,$sdom)));
- $r->print(
- '
'."\n");
+ }
}
-# ================================================= Drop/Add from uploaded file
-sub upfile_drop_add {
- my $r=shift;
+#
+# 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.